import { PrismaService } from '@/common/modules/prisma/prisma.service'
import { Injectable } from '@nestjs/common'
import { updateUserDto } from './dto/userInfo.dto'

@Injectable()
export class UserService {
  constructor(private prisma: PrismaService) {}
  async updateUserInfo(id: number, data: updateUserDto) {
    const whereObj: any = {}
    data.avatar_url && (whereObj.avatar_url = data.avatar_url)
    data.autograph && (whereObj.autograph = data.autograph)
    data.nickName && (whereObj.nickName = data.nickName)
    data.gender && (whereObj.gender = data.gender)
    const res = await this.prisma.user.update({
      where: { id },
      data: whereObj,
    })
    if (res && res.id) {
      return 'ok'
    } else {
      return 'error'
    }
  }
}
